#if 0x0
class T_NetworkAccessBackendFactory; //
class T_NetworkAccessManager;        //
class T_HttpAccessBackend;           //
class T_HttpAccessReply_Base;        //
class T_HttpAccessReply;             //
class T_HttpAccessReplyBackend;      //

#ifndef NAM_H
#define NAM_H

#include "../t_core.h"
#include <QtCore>
#include <QtNetwork>
////#include "private/qnetworkaccessbackend_p.h"

class T_NetworkAccessBackendFactory : public QObject
{
    Q_OBJECT
public:
    explicit T_NetworkAccessBackendFactory(QObject * parent = 0) : QObject(parent) {  }
    virtual ~T_NetworkAccessBackendFactory() {  }
    virtual QObject *create(T_NetworkAccessManager * nam,
                            QNetworkAccessManager::Operation op,
                            const QNetworkRequest & request,
                            QIODevice * outgoingData) const
    { return NULL; }
};

class T_NetworkAccessManager : public QNetworkAccessManager
{
    Q_OBJECT
public:
    explicit T_NetworkAccessManager(QObject *parent = 0);
    virtual QNetworkReply *createRequest(
            Operation op,
            const QNetworkRequest & request,
            QIODevice * outgoingData = 0);
    virtual QNetworkReply *createRequestWithBackend(
            Operation op,
            const QNetworkRequest &request,
            QIODevice *outgoingData = 0,
            QObject *backend = 0);
    void appendBackendFactory(T_NetworkAccessBackendFactory *a_factory);
    void prependBackendFactory(T_NetworkAccessBackendFactory *a_factory);
    void addToSilentList(QRegExp a_rx);
protected:
    virtual QNetworkAccessBackend *createBackend(QNetworkAccessManager::Operation op,
                                                 const QNetworkRequest & request,
                                                 QIODevice * outgoingData)
    {
        Q_UNUSED(op); Q_UNUSED(request); Q_UNUSED(outgoingData);
        return NULL;
    }
protected:
    QList<T_NetworkAccessBackendFactory *> f_factory_list;
    T_Locked f_factory_list_lock;
    QList<QRegExp> f_silent_list;
};

class T_HttpAccessBackend: public QNetworkAccessBackend
{
    Q_OBJECT
public:
    explicit T_HttpAccessBackend(T_NetworkAccessManager * nam);
    virtual ~T_HttpAccessBackend();

    //
    virtual T_HttpAccessReply_Base *createHttpReply() = 0;
    //
    T_NetworkAccessManager *networkAccessManager();
    //
    QIODevice *uploadDevice();
    void setUploadDevice(QIODevice *a_device);
    //
    virtual void open();
    virtual void downstreamReadyWrite();
    // this indicates that the user closed the stream while the reply isn't finished yet
    virtual void closeDownstreamChannel() {}
    // HTTP backend does not support waitForReadyRead()
    virtual bool waitForDownstreamReadyRead(int msecs) { return false; }
    // we return true since HTTP needs to send PUT/POST data again after having authenticated
    virtual bool needsResetableUploadData() { return true; }
    virtual void copyFinished(QIODevice *dev);
    // SSL
    virtual void ignoreSslErrors();
    virtual void ignoreSslErrors(const QList<QSslError> & errors);
    virtual void fetchSslConfiguration(QSslConfiguration & config) const;
    virtual void setSslConfiguration(const QSslConfiguration & config);

//public slots:

private slots:
    void finished(); // override
    void namAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
    void replyAuthenticationRequired(QAuthenticator *authenticator);
    void replyReadyRead();
    void replyFinished();
    void replyMetaDataChanged();
    void replyError(QNetworkReply::NetworkError errorCode);
    void replyUploadProgress(qint64 bytesSent, qint64 bytesTotal);
    void replyDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);

private:
    T_NetworkAccessManager *f_nam;
    T_HttpAccessReply_Base *f_httpReply;
    ////T_HttpAccessReply *f_httpReply;
    QIODevice *f_uploadDevice;
#ifndef QT_NO_OPENSSL
    QSslConfiguration *f_pendingSslConfiguration;
    bool f_pendingIgnoreAllSslErrors;
    QList<QSslError> f_pendingIgnoreSslErrorsList;
#endif

    void p_disconnectFromHttp();
    void p_readFromHttp();
    void p_checkForRedirect(const int statusCode);
};

class T_HttpAccessReply_Base
{
protected:
    T_HttpAccessBackend *f_backend;
public:
    explicit T_HttpAccessReply_Base(T_HttpAccessBackend *backend)
        : f_backend(backend)
    {
    }
    virtual ~T_HttpAccessReply_Base()
    {
    }
    // start()
    virtual void start(T_NetworkAccessManager * nam,
                       QNetworkAccessManager::Operation op,
                       const QNetworkRequest & request,
                       QIODevice * outgoingData) = 0;
    // me()
    QObject *me()
    {
        return dynamic_cast<QObject *>(this);
    }
    // backend()
    T_HttpAccessBackend *backend()
    {
        return f_backend;
    }
    // raw headers:
    virtual bool hasRawHeader(const QByteArray &headerName) const = 0;
    virtual QList<QByteArray> rawHeaderList() const = 0;
    virtual QByteArray rawHeader(const QByteArray &headerName) const = 0;
    // attributes
    virtual QVariant attribute(QNetworkRequest::Attribute code) const = 0;
    // reading
    virtual qint64 bytesAvailable() = 0;
    virtual QByteArray read(qint64 a_max) = 0;
    // errorString()
    virtual QString errorString() const
    {
        return "";
    }
    // SSL
    virtual void ignoreSslErrors()
    {
    }
    virtual void ignoreSslErrors(const QList<QSslError> & errors)
    {
    }
    virtual QSslConfiguration sslConfiguration() const
    {
        return QSslConfiguration::defaultConfiguration();
    }
    virtual void setSslConfiguration(const QSslConfiguration & config)
    {
    }
    //[metaDataChanged()]
    void enqueue_metaDataChanged()
    {
        QMetaObject::invokeMethod(me(), "emit_metaDataChanged", Qt::QueuedConnection);
    }
    //[readyRead()]
    void enqueue_readyRead()
    {
        QMetaObject::invokeMethod(me(), "emit_readyRead", Qt::QueuedConnection);
    }
    //[finished()]
    void enqueue_finished()
    {
        QObject *me = dynamic_cast<QObject *>(this);
        QMetaObject::invokeMethod(me, "emit_finished", Qt::QueuedConnection);
    }
protected:
    virtual void p_connectQNetworkReply(QNetworkReply * a_netReply)
    {
        //NAM::authenticationRequired()
        me()->connect(a_netReply->manager(),
                      SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
                      SLOT(emit_namAuthenticationRequired(QNetworkReply*,QAuthenticator*)));
        //readyRead()
        me()->connect(a_netReply, SIGNAL(readyRead()), SLOT(emit_readyRead()));
        //metaDataChanged()
        me()->connect(a_netReply, SIGNAL(metaDataChanged()), SLOT(emit_metaDataChanged()));
        //finished()
        me()->connect(a_netReply, SIGNAL(finished()), SLOT(emit_finished()));
        //error()
        me()->connect(a_netReply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(emit_error(QNetworkReply::NetworkError)));
        //uploadProgress()
        me()->connect(a_netReply, SIGNAL(uploadProgress(qint64,qint64)), SLOT(emit_uploadProgress(qint64,qint64)));
#ifndef QT_NO_OPENSSL
        me()->connect(a_netReply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(emit_sslErrors(QList<QSslError>)));
#endif
    }
};

class T_HttpAccessReply : public QObject, public T_HttpAccessReply_Base
{
    Q_OBJECT
public:
    explicit T_HttpAccessReply(T_HttpAccessBackend *parent)
        : QObject(parent)
        , T_HttpAccessReply_Base(parent)
    {
    }
    virtual ~T_HttpAccessReply()
    {
    }

Q_SIGNALS:
    void impl_authenticationRequired(QAuthenticator *authenticator); // from QNetworkAccessManager
    void impl_metaDataChanged();
    void impl_readyRead();
    void impl_finished();
    void impl_error(QNetworkReply::NetworkError code);
    void impl_uploadProgress(qint64 bytesSent, qint64 bytesTotal);
    void impl_sslErrors(const QList<QSslError> & errors);
protected Q_SLOTS:
    // emit handlers
    virtual void emit_namAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
    {
        Q_UNUSED(reply);
        emit impl_authenticationRequired(authenticator);
    }
    //[metaDataChanged()]
    virtual void emit_metaDataChanged() { emit impl_metaDataChanged(); }
    //[readyRead()]
    virtual void emit_readyRead() { emit impl_readyRead(); }
    //[finished()]
    virtual void emit_finished() { emit impl_finished(); }
    //[error()]
    virtual void emit_error(QNetworkReply::NetworkError code) { emit impl_error(code); }
    //[uploadProgress()]
    virtual void emit_uploadProgress(qint64 bytesSent, qint64 bytesTotal)
    {
        emit impl_uploadProgress(bytesSent, bytesTotal);
    }
#ifndef QT_NO_OPENSSL
    //[sslErrors()]
    virtual void emit_sslErrors(const QList<QSslError> & errors)
    {
        emit impl_sslErrors(errors);
    }
#endif
};

class T_HttpAccessReplyBackend : public T_HttpAccessBackend, public T_HttpAccessReply_Base
{
    Q_OBJECT
public:
    explicit T_HttpAccessReplyBackend(T_NetworkAccessManager * nam)
        : T_HttpAccessBackend(nam)
        , T_HttpAccessReply_Base(this)
    {
    }
    virtual T_HttpAccessReply_Base *createHttpReply()
    {
        return this;
    }
Q_SIGNALS:
    void impl_authenticationRequired(QAuthenticator *authenticator); // from QNetworkAccessManager
    void impl_metaDataChanged();
    void impl_readyRead();
    void impl_finished();
    void impl_error(QNetworkReply::NetworkError code);
    void impl_uploadProgress(qint64 bytesSent, qint64 bytesTotal);
    void impl_sslErrors(const QList<QSslError> & errors);
protected Q_SLOTS:
    // emit handlers
    virtual void emit_namAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
    {
        Q_UNUSED(reply);
        emit impl_authenticationRequired(authenticator);
    }
    //[metaDataChanged()]
    virtual void emit_metaDataChanged() { emit impl_metaDataChanged(); }
    //[readyRead()]
    virtual void emit_readyRead() { emit impl_readyRead(); }
    //[finished()]
    virtual void emit_finished() { emit impl_finished(); }
    //[error()]
    virtual void emit_error(QNetworkReply::NetworkError code) { emit impl_error(code); }
    //[uploadProgress()]
    virtual void emit_uploadProgress(qint64 bytesSent, qint64 bytesTotal)
    {
        emit impl_uploadProgress(bytesSent, bytesTotal);
    }
#ifndef QT_NO_OPENSSL
    //[sslErrors()]
    virtual void emit_sslErrors(const QList<QSslError> & errors)
    {
        emit impl_sslErrors(errors);
    }
#endif
};

class T_HttpAccessReply_QNetworkReply : public T_HttpAccessReply
{
    Q_OBJECT
public:
    //ctor
    explicit T_HttpAccessReply_QNetworkReply(T_HttpAccessBackend *parent,
                                             QNetworkReply *a_reply = 0);
    //dtor
    virtual ~T_HttpAccessReply_QNetworkReply();
    // raw headers:
    virtual bool hasRawHeader(const QByteArray &headerName) const;
    virtual QList<QByteArray> rawHeaderList() const;
    virtual QByteArray rawHeader(const QByteArray &headerName) const;
    // attributes
    virtual QVariant attribute(QNetworkRequest::Attribute code) const;
    // reading
    virtual qint64 bytesAvailable();
    virtual QByteArray read(qint64 a_max);
    // errorString()
    virtual QString errorString() const;
    // SSL
    virtual void ignoreSslErrors();
    virtual void ignoreSslErrors(const QList<QSslError> & errors);
    virtual QSslConfiguration sslConfiguration() const;
    virtual void setSslConfiguration(const QSslConfiguration & config);
protected:
    QNetworkReply *m_netReply;
};

#endif // NAM_H
#endif // 0
